<template>
  <div>
    <h1>我负责的理赔订单列表</h1>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column fixed prop="startTime" label="日期" width="150"></el-table-column>
      <el-table-column prop="ordersId.productsId.name" label="保险名称" width="120"></el-table-column>
      <el-table-column prop="salesmanId.userName" label="所属销售员" width="120"></el-table-column>
      <el-table-column prop="reason" label="理赔原因" width="120"></el-table-column>
      <el-table-column prop="img" label="理赔凭证" width="300">
        <template slot-scope="scope">
          <img
            width="60"
            v-if="scope.row.img"
            :src="'http://localhost:3000/temp/'+scope.row.img"
            alt
          />
          <img width="60" v-else src="http://localhost:3000/default/default.jpg" alt />
        </template>
      </el-table-column>
      <el-table-column prop="state" label="理赔状态" width="120"></el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="deleteOneClaim(scope.row)" type="text" size="small">删除</el-button>
          <el-button type="text" size="small" @click="xiugai(scope.row._id)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import api from "../../../network/apis/api";
import { log } from "util";
export default {
  created() {
    this.getAllClaims();
  },
  methods: {
    handleClick(row) {
      console.log(row._id);
    },
    async deleteOneClaim(row) {
      const data = await api.claims.deleteOneClaim(row._id);
      this.getAllClaims();
    },
    xiugai(id) {
      this.$router.push("/salesman/UpdateClaim/" + id);
    },
    async getAllClaims() {
      var adc = 1;
      const { data } = await api.claims.getAllClaims();
      console.log(data);
      if (data.status) {
        const shuju = data.data.filter(item => {
          if (item.salesmanId._id == localStorage._id) {
            return (adc = 10);
          }
        });
        this.tableData = shuju;
        for (let i = 0; i < this.tableData.length; i++) {
          if (this.tableData[i].state == 0) {
            this.tableData[i].state = "待处理";
          } else if (this.tableData[i].state == 1) {
            this.tableData[i].state = "申请成功";
          } else if (this.tableData[i].state == -1) {
            this.tableData[i].state = "申请失败";
          }
        }
      }
    }
  },

  data() {
    return {
      tableData: [
        {
          img: "",
          ordersId: {},
          reason: "",
          salesmanId: {},
          startTime: "2020-09-19",
          state: 0,
          _id: ""
        }
      ]
    };
  }
};
</script>

<style>
</style>